# 作业二：
# 请设计一个装饰器，它可以作用于任何函数上，打印函数执行时间

# 统计函数运行时间
import time
def printRunTime(func):
    def run_time(*args, **kwargs):
        start_time = time.time()
        ret = func(*args, **kwargs)
        print(f'{func.__name__} run cost time: {time.time() - start_time}')
        return ret
    return run_time

@printRunTime   # 等于 add = printRunTime(add)
def add(x, y):
    print(f'{x} + {y} = {x + y}')

add(1, 2)


@printRunTime
def sleepTest(n):
    time.sleep(n)

sleepTest(10)